package com.example.statistics.ui.yw

import com.example.statistics.bean.DefineInputBean
import com.example.statistics.bean.yw.MaterialBean
import com.example.statistics.common.BaseInputActivity
import com.example.statistics.ex.isNumber
import com.example.statistics.ex.mulEx
import com.example.statistics.ex.textStringToNumber
import com.example.statistics.net.UrlConfig
import com.example.statistics.weight.TextProcessingView

/**
 * 原料入库、修改
 */
open class MaterialAddActivity : BaseInputActivity<MaterialBean>() {


    override val title: String
        get() = "原料"

    override val url: String
        get() = UrlConfig.MATERIAL_ADD

    override val inputDataList: List<DefineInputBean>
        get() = listOf(
            DefineInputBean("日        期：", "date", TextProcessingView.STYLE_DATE),
            DefineInputBean("商        品：", "materialName", TextProcessingView.STYLE_INPUT),
            DefineInputBean("规        格：", "specification", TextProcessingView.STYLE_SELECTOR,
                singleDialog = Pair(listOf("5", "10", "15", "20", "25")) { str, list ->
                    if (list["materialNumber"]?.contentText.isNumber()) {
                        val weight = list["materialNumber"]?.textStringToNumber.mulEx(str.toDouble()).toString()
                        list["materialWeight"]?.contentText = weight
                    }
                    if (list["checkoutNumber"]?.contentText.isNumber()) {
                        val weight = list["checkoutNumber"]?.textStringToNumber.mulEx(str.toDouble()).toString()
                        list["checkoutWeight"]?.contentText = weight
                    }
                }),
          /*  DefineInputBean("到货件数：", "materialNumber", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber()) {
                        extentParams.add("inventoryNumber" to str)
                        if (list["specification"]?.contentText.isNumber()) { // 规格不为空计算重量
                            val specification = list["specification"]?.textStringToNumber
                            list["materialWeight"]?.contentText = specification.mulEx(str.toDouble()).toString()
                        }
                        list["checkoutNumber"]?.contentText = str
                    }
                }),
            DefineInputBean("结账件数：", "checkoutNumber", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber()) {
                        extentParams.add("inventoryWeight" to str)
                        if (list["specification"]?.contentText.isNumber()) { // 规格不为空计算重量
                            val specification = list["specification"]?.textStringToNumber
                            list["checkoutWeight"]?.contentText = specification.mulEx(str.toDouble()).toString()
                        }
                    }
                }),
            DefineInputBean("到货重量：", "materialWeight", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber()) {
                        if (list["unitPrice"]?.contentText.isNumber()) { // 单价不为空计算总价
                            val unitPrice = list["unitPrice"]?.textStringToNumber
                            list["totalPrice"]?.contentText = unitPrice.mulEx(str.toDouble()).toString()
                        }
                    }
                }),
            DefineInputBean("结账重量：", "checkoutWeight", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber()) {
                        if (list["unitPrice"]?.contentText.isNumber()) { // 单价不为空计算总价
                            val unitPrice = list["unitPrice"]?.textStringToNumber
                            list["checkoutPrice"]?.contentText = unitPrice.mulEx(str.toDouble()).toString()
                        }
                    }
                }),
            DefineInputBean("单价(KG)：", "unitPrice", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->
                    if (str.isNumber()) {
                        if (list["checkoutWeight"]?.contentText.isNumber()) { // 单价不为空计算总价
                            val checkoutWeight = list["checkoutWeight"]?.textStringToNumber
                            list["checkoutPrice"]?.contentText = checkoutWeight.mulEx(str.toDouble()).toString()
                        }
                        if (list["materialWeight"]?.contentText.isNumber()) { // 单价不为空计算总价
                            val checkoutWeight = list["materialWeight"]?.textStringToNumber
                            list["totalPrice"]?.contentText = checkoutWeight.mulEx(str.toDouble()).toString()
                        }
                    }
                }),*/
            DefineInputBean("到货金额：", "totalPrice", TextProcessingView.STYLE_INPUT_FLOAT,
                afterTextChangeListener = { str, list ->

                }),
            DefineInputBean("结账金额：", "checkoutPrice", TextProcessingView.STYLE_INPUT_FLOAT),
            DefineInputBean("运        费：", "freight", TextProcessingView.STYLE_INPUT_FLOAT),
            DefineInputBean("其他费用：", "otherPrice", TextProcessingView.STYLE_INPUT_FLOAT),
            DefineInputBean("备        注：", "remark", TextProcessingView.STYLE_INPUT),
        )

}